<?php
	require_once("FileUploadHandler.php");
	
	class FileUploadView {
		private $m_uploadButton = "upload";
		private $m_file = "file";
		
		/**
		 * FileUpload form
		 * @return string HTML
		 */
		public function DoFileUploadBox() {
			return "<div>
						<form method='post' enctype='multipart/form-data'>
			 				<fieldset>
			 					<label for='$this->m_file'>File: </label>
			 					<input type='file' name='$this->m_file' />
			 					<input type='submit' name='$this->m_uploadButton' value='Upload' />
			 				</fieldset>
						</form>
					</div>";
		}
		
		/**
		 * Gets file from input
		 * @return binary $file
		 */
		public function GetFile() {
			if(isset($_FILES[$this->m_file])) {
				return $_FILES[$this->m_file];
			}			
			return null;
		}
		
		/**
		 * Gets upload button pressed
		 * @return boolean
		 */
		public function TriedToUpload() {
			if(isset($_POST[$this->m_uploadButton])) {
				return true;
			}
			return false;
		}
		 
		/**
		 * FileList
		 * @return string HTML
		 */
		public function DoFileListBox() {
		 	$fuh = new FileUploadHandler();
			
			$list = $fuh->GetFileList();
			
			$html = "<div>
						<h2>File-List</h2>
						<ul>";
			for ($a = 0; $a < count($list); $a++) {
				$html .= "<li>";
				for ($b = 0; $b < count($list[$a]); $b++) {
					if ($b == 0) {
						$html .= "<a href='".$list[$a][$b]."'>";
					} else if ($b == 1) {
						$html .= $list[$a][$b]."</a>   ";
					} else {
						$html .= $list[$a][$b]."   ";
					}
				}
				$html .= "</li>"; 
			}
			
			$html .= "	</ul>
					</div>";
			
			return $html;
		}
	}
?>